<template>
  <div id="mine-team-achievement">
    <achievement
      v-if="infoReady"
      :headers="headers"
      :lists="lists"
      attrOneName="name"
      attrTwoName="amount"></achievement>
  </div>
</template>

<script>
  import Achievement from '../comp/achievement.vue';
  export default {
    name: "mine-team-achievement",
    components: {
      Achievement
    },
    data() {
      return {
        headers: [
          '团队名称',
          '团队业绩'
        ],
        lists: [
          {
            text: '全部',
            contents: [], // 根据后台接口数据格式 name、amount
          },
          {
            text: '本日',
            contents: [],
          },
          {
            text: '本月',
            contents: [],
          },
          {
            text: '本年',
            contents: [],
          }
        ],
        infoReady: false
      }
    },
    methods: {
      getInfo(type) {
        this.$http.post({
          api: this.$api.USER_TEAM_ACHIEVEMENT,
          params: {
            user_id: localStorage.getItem('id'),
            type: type + 1
          },
          success: (res) => {
            this.lists[type].contents = res.data.data;
          }
        });
      }
    },
    created() {
      for (let i = 0; i < 4; i++) {
        this.getInfo(i);

        if (i === 3) {
          this.infoReady = true;
        }
      }
    }
  }
</script>

<style scoped lang="scss"></style>
